let store = JSON.parse(sessionStorage.getItem('store'));
let objectDate = {
	'moduleType':2,
	'competitionType': store.competitionType ?? null
};

$.ajax({
	cache : true,
	type : "POST",
	url:'/jz-jinzhuan-disposition-module/getModuleList',
	data : JSON.stringify(objectDate),// 你的formid
	async : false,
	headers: {
		'Content-Type':'application/json;charset=UTF-8'
	},
	error : function(request) {
		parent.layer.alert("Connection error");
	},

	success : function(data) {
		let str = '', srr;
		if (data.code == 0) {
			sessionStorage.setItem('vs',JSON.stringify(data.data));
			$.each(data.data,function (k,v){
				if( k == 0 ){
					str += `<option value="">请选择</option>`;
				}
				str += `<option value="${v.id}">${v.moduleName}</option>`;
			})
			$("#templet").html(str);
		} else {
			parent.layer.alert(data.msg)
		}

	}
})

$('body').on('change','#templet',function (ev){
	let vs = JSON.parse(sessionStorage.getItem('vs'));
	let exam = $(this).find("option:selected").index();
	let sar = '';
	if( exam - 1 < 0 ){
		$("#templetScore").html('');
	}else{
		vs = vs[exam-1];
	}

	if( $(this).find("option:selected").val() == vs.id ){

		vs.dispositionTopic.map(function (v){
			sar += `<li><span>任务名称:${v.topicName}</span>  <span>任务分数:${v.score}</span></li>`
		})
		$("#templetScore").html(sar);

	}

})

function save() {
	// validateRule();

	if( !$("#name").val() ){
		layer.msg('请选择考场')
		return false;
	}

	if( !$("#templet").val() ){
		layer.msg('请选择考试模版')
		return false;
	}

	if( !$("#startTime").val() ){
		layer.msg('请选择考试开始时间')
		return false;
	}

	if( !$("#endTime").val() ){
		layer.msg('请选择考试结束时间')
		return false;
	}

	$.ajax({
		cache : true,
		type : "POST",
		url : "/jzweb/examinationBatchComS/save",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}

layui.use(['laydate','xmSelect'],function (){
	var laydate = layui.laydate;

	laydate.render({
		elem: '#startTime'
		,type: 'datetime'
	});
	laydate.render({
		elem: '#endTime'
		,type: 'datetime'
	});

})
